package 反射;

import java.lang.annotation.*;

public  class  Test10{

    public static void main(String[] args) throws ClassNotFoundException {
        Class c1 = Class.forName("反射.student");
        //通过反射获得注解
        Annotation[] annotations = c1.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
        //通过反射获得指定注解的value值
        FieldFan annotation = (FieldFan) c1.getAnnotation(FieldFan.class);
        System.out.println(annotation);


    }

}
@KuangFan("Student")
class student {
    @FieldFan(columnName = "id",type = "int",length = 10)
    private  int id;
    @FieldFan(columnName = "name",type = "String",length = 30)
    private  String  name;
    @FieldFan(columnName = "age",type = "int",length = 5)
    private   int  age;

    public student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public student() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Test10{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface   KuangFan{
    String  value();
}
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface FieldFan{
    String  columnName();
    String  type();
    int  length();
}
